package c09_stream_middle_method;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Test {
    public static void main(String[] args) {
        List<Student11>students= new ArrayList<>();

        students.add(new Student11("小王王", 18, 66));
        students.add(new Student11("小张", 17, 99));
        students.add(new Student11("小李", 26, 20));
        students.add(new Student11("小赵", 16, 77));
        students.add(new Student11("小刘", 19, 18));
        students.add(new Student11("小李", 26, 20));

        //stream.filter(s->s.getKor()>80).forEach(System.out::println);
        students.stream()
                .filter(s -> s.getScore() > 60)
                .sorted((s1, s2) -> Double.compare(s2.getScore(), s1.getScore()))
                .forEach(System.out::println);
        System.out.println("====================");
        students.stream().filter(s -> s.getAge() > 18)
                .filter(s -> s.getAge() < 25)
                .sorted((s1, s2) -> Double.compare(s2.getScore(), s1.getScore()))
                .forEach(System.out::println);
        System.out.println("====================");


        students.stream()
                .sorted((s1,s2)-> Double .compare(s2.getScore(), s1.getScore()))
                .limit(3)
                .forEach( System.out::println);
        System.out.println( "====================");

        students.stream()
                .sorted((s1,s2)-> Double .compare(s1.getScore(), s2.getScore()))
                .skip(students.size()-3)
                .forEach( System.out::println);
        System.out.println( "====================");

        students.stream()
                .filter(s->s.getAge()>18)
                .distinct()
                .forEach(System.out::println);
        System.out.println( "====================");

        students.stream()
                .filter(s->s.getScore()>=60)
                .map(s->new Teacher11(s.getName(),s.getAge(),s.getScore()))
                .sorted((t1,t2)->t1.getAge()-t2.getAge())
                .forEach(System.out::println);
        System.out.println( "====================");
        Stream<Student11> s1 = students.stream()
                .filter(s->s.getAge()<18);
        Stream<Student11> s2 = students.stream()
                .filter(s->s.getScore()<60);
        Stream.concat(s1,s2).forEach(System.out::println);
        System.out.println( "====================");
        long count = students.stream()
                .filter(s->s.getName().length()==3)
                .count();
        System.out.println("三个字学生的数量： "+count);

        Optional<Student11> op = students.stream()
                .min((student1, student2)->Double.compare(student1.getScore(), student2.getScore()));
        Student11 st2 = op.get();
        System.out.println("考试最后学生"+st2);
        System.out.println( "====================");
        List<Student11> collect = students.stream()
                .filter(s->s.getScore()>60)
                .collect(Collectors.toList());
        System.out.println(collect);
         System.out.println( "====================");
         Set<Student11> collect1 = students.stream()
                 .filter(s->s.getScore()>60)
                 .collect(Collectors.toSet());
         System.out.println(collect1);
         System.out.println( "====================");
        Map<String, Student11> collect2 = students.stream()
                .filter(s->s.getScore()>60)
                .collect(Collectors.toMap(Student11::getName, s -> s));
        System.out.println(collect2);
         System.out.println( "====================");
    }



}
